package com.example.administrator.android2019.cg6service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class MyImageService extends Service {
    public MyImageService() {
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        throw new UnsupportedOperationException("Not yet implemented");
    }

    @Override
    public void onCreate() {
        super.onCreate();

    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.v("image","Service"+Thread.currentThread().getName());
        /*2、模拟下载图片任务
        */
       // try {
            Log.v("image","Service开始下载图片");
            /*
            * 让线程休眠3秒，这3秒内，界面不能动
            * 若线程休眠超过5秒：
            *  1）、界面不能动且会报错（服务中耗时操作要放在子线程）
            *  2）、但是服务中的任务还会继续执行（原因：服务的运行并不依赖于用户可视界面Ui）
            * */
         //   Thread.sleep(3000);
           // Log.v("image","Service图片下载完毕");
        //} catch (InterruptedException e) {
           // e.printStackTrace();
        //}

        MyImageThread myImageThread=new MyImageThread();
        return super.onStartCommand(intent, flags, startId);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
    }
}
